﻿using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace EditColumn.ConnectColumnBream
{
	internal class ViewDefining
	{
		public ViewDefining(ExternalCommandData commandData)
		{
			this.m_commandData = commandData;
			this.m_uiDoc = commandData.Application.ActiveUIDocument;
			this.m_doc = this.m_uiDoc.Document;
			this.m_uiApp = commandData.Application;
		}

		public void CreateViewDefining(ConnectColumnBreamInfo connectColumnBreamInfo)
		{
			this.OpenView(connectColumnBreamInfo.ConnectBreamInfo.BreamViewPlan);
			XYZ xyz = new XYZ(connectColumnBreamInfo.ConnectPoint.X - BreamConnectColumnGeometryToos.OneMillimeter * 3000.0, connectColumnBreamInfo.ConnectPoint.Y - BreamConnectColumnGeometryToos.OneMillimeter * 3000.0, 0.0);
			XYZ xyz2 = new XYZ(connectColumnBreamInfo.ConnectPoint.X + BreamConnectColumnGeometryToos.OneMillimeter * 3000.0, connectColumnBreamInfo.ConnectPoint.Y + BreamConnectColumnGeometryToos.OneMillimeter * 3000.0, 0.0);
			List<UIView> list = this.m_uiDoc.GetOpenUIViews().ToList<UIView>();
			UIView uiview = null;
			foreach (UIView uiview2 in list)
			{
				if (uiview2.ViewId.IntegerValue == connectColumnBreamInfo.ConnectBreamInfo.BreamViewPlan.Id.IntegerValue)
				{
					uiview = uiview2;
					break;
				}
			}
			uiview.ZoomAndCenterRectangle(xyz, xyz2);
			this.MiddleShow(connectColumnBreamInfo.ConnectBreamInfo.Bream.Id);
		}

		private void OpenView(ViewPlan view)
		{
			this.m_uiApp.ActiveUIDocument.ActiveView = view;
		}

		private void MiddleShow(ElementId breamId)
		{
			List<ElementId> list = new List<ElementId>();
			list.Add(breamId);
			this.m_uiDoc.Selection.SetElementIds(list);
		}

		private ExternalCommandData m_commandData;

		private UIDocument m_uiDoc;

		private Document m_doc;

		private UIApplication m_uiApp;
	}
}
